/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.jr2tecnologia.model.persistence;

import br.com.jr2tecnologia.LoggerFactory;
import br.com.jr2tecnologia.model.entity.Carrier;
import br.com.jr2tecnologia.model.repository.CarrierRepository;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author ronildo
 */
public class CarrierDAO extends GenericDAO<Carrier, CarrierRepository> implements CarrierRepository {
    
    private static final Logger logger = LoggerFactory.getLogger();

    public Carrier findById(Long id) {
        return (Carrier)em.createNamedQuery("Carrier.findByPkCarrier").
                setParameter("pkCarrier", id).getSingleResult();
    }

    public List<Carrier> list(){
        String sql = "SELECT c FROM Carrier c";
        return em.createQuery(sql).getResultList();
        
    }

    public List<Carrier> listAll(){
        try{
            return em.createNamedQuery("Carrier.findAll").getResultList();
        }catch(IllegalStateException e){
            logger.log(Level.SEVERE, msg, e);
            throw new DAOException(e);
        }
    }
}
